package com.sbj.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.MemberReq;
import com.sbj.dto.req.OrderTimeReq;
import com.sbj.dto.res.AddressRes;
import com.sbj.dto.res.MemberRes;
import com.sbj.service.IAddressService;
import com.sbj.service.IMemberService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author summer
 * @since 2024/08/10 10:02:41
 */
@RestController
@RequestMapping("/member")
@AllArgsConstructor
public class MemberController implements BaseCommonInterface<MemberReq, MemberRes> {

    private final IMemberService memberService;

    @Override
    public Result<String> save(@Valid MemberReq memberReq) {
        return null;
    }

    @Override
    public Result<String> del(Integer integer) {
        return null;
    }

    @Override
    public Result<Page<MemberRes>> lists(MemberReq memberReq) {
        return Result.successResult(memberService.lists(memberReq));
    }

    @Override
    public Result<MemberRes> findById(Integer integer) {
        return null;
    }

    @Override
    public Result<String> batchDel(List<MemberRes> list) {
        return null;
    }

    private final IAddressService addressService;

    @GetMapping(value = "/memberAddress/{id}")
    public Result<AddressRes> memberAddress(@PathVariable Integer id) {
        AddressRes addressRes= addressService.memberAddress(id);
        return Result.successResult(addressRes);
    }

    /**
     * 保存会员抢单时间
     * @param orderTimeReq
     * @return
     */
    @PostMapping(value = "/saveMemberOrderTime")
    public Result<String> saveMemberOrderTime(@RequestBody OrderTimeReq orderTimeReq) {
        memberService.saveMemberOrderTime(orderTimeReq);
        return Result.successResult();
    }

    /**
     * 更新特权
     * @param memberReq
     * @return
     */
    @PostMapping(value = "/savePrivilege")
    public Result<String> savePrivilege(@RequestBody MemberReq memberReq) {
        memberService.savePrivilege(memberReq);
        return Result.successResult();
    }
}
